﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Gmantis.Controls.Chart
{
    internal interface ICustomClipping
    {
    }

    public class Bar : PlotElement, ICustomClipping
    {
        // Fields
        protected RectangleGeometry geometry = new RectangleGeometry();

        // Methods
        public Bar()
        {
            ((Path)base.Shape).Data = this.geometry;
        }

        internal override object Clone()
        {
            Bar clone = new Bar();
            base.CloneAttributes(clone);
            clone.RadiusX = this.RadiusX;
            clone.RadiusY = this.RadiusY;
            return clone;
        }

        protected override bool Render(RenderContext rc)
        {
            if (this.RadiusX == 0.0)
            {
                this.RadiusX = BarColumnOptions.GetRadiusX(rc.Chart);
            }
            if (this.RadiusY == 0.0)
            {
                this.RadiusY = BarColumnOptions.GetRadiusY(rc.Chart);
            }
            if (double.IsInfinity(rc.Rect.Width) || double.IsInfinity(rc.Rect.Height))
            {
                return false;
            }
            Rect rect = rc.Rect;
            if (double.IsNaN(rect.X) || double.IsNaN(rect.Y))
            {
                return false;
            }
            if ((rect.Width == 0.0) || (rect.Height == 0.0))
            {
                BaseRenderer renderer = rc.Renderer as BaseRenderer;
                if ((renderer != null) && (renderer.Stacked != StackedOptions.None))
                {
                    return false;
                }
            }
            rect = rect.IntersectRect(rc.Bounds);
            if (rect.IsEmptyRect())
            {
                return false;
            }
            this.geometry.Rect = new Rect(0.0, 0.0, rect.Width, rect.Height);
            Canvas.SetLeft(this, rect.X);
            Canvas.SetTop(this, rect.Y);
            Rect clipBounds = rc.ClipBounds;
            clipBounds.X -= rect.X;
            clipBounds.Y -= rect.Y;
            RectangleGeometry geometry2 = new RectangleGeometry
            {
                Rect = clipBounds
            };
            base.Clip = geometry2;
            return true;
        }

        // Properties
        protected override bool IsClustered
        {
            get
            {
                return true;
            }
        }

        public double RadiusX
        {
            get
            {
                return this.geometry.RadiusX;
            }
            set
            {
                this.geometry.RadiusX = value;
            }
        }

        public double RadiusY
        {
            get
            {
                return this.geometry.RadiusY;
            }
            set
            {
                this.geometry.RadiusY = value;
            }
        }
    }
}
